using System;
using System.Collections.Generic;

namespace SY.WebSite.Entity
{
	/// <summary>
	///	
	/// </summary>
	[Serializable]
	public class KeyValue : IEntity
	{
		public const string RESERVE_CONST = "KeyValue";
			
		#region Private Members
		private int _id; 
		private string _key; 
		private string _value; 
		private int _type; 		
		[NonSerialized]
        private string _reserve;
		#endregion
		
		#region Default ( Empty ) Class Constuctor
		/// <summary>
		/// default constructor
		/// </summary>
		public KeyValue()
		{
			_id = 0; 
			_key = null; 
			_value = null; 
			_type = 0; 
		}
		#endregion // End of Default ( Empty ) Class Constuctor
		
		public Dictionary<string, object> ToDictionary()
		{
			Dictionary<string, object> dictionary = new Dictionary<string, object>();
		
			dictionary.Add("Id",_id);
			dictionary.Add("Key",_key);
			dictionary.Add("Value",_value);
			dictionary.Add("Type",_type);
			
			dictionary.Add("Reserve",Reserve);//特殊
			return dictionary;
		}
		
		#region Public Properties
		/// <summary>
		/// 
		/// </summary>		
		public int Id
		{
			get { return _id; }
			set { _id = value; }
		}
			
		/// <summary>
		/// 
		/// </summary>		
		public string Key
		{
			get { return _key; }
			set	
			{
				if( value!= null && value.Length > 50)
					throw new ArgumentOutOfRangeException(@"Invalid value for Key", value, value);
				
				_key = value;
			}
		}
			
		/// <summary>
		/// 
		/// </summary>		
		public string Value
		{
			get { return _value; }
			set	
			{
				if( value!= null && value.Length > 2000)
					throw new ArgumentOutOfRangeException(@"Invalid value for Value", value, value);
				
				_value = value;
			}
		}
			
		/// <summary>
		/// 
		/// </summary>		
		public int Type
		{
			get { return _type; }
			set { _type = value; }
		}
			
		/// <summary>
        /// 保留属性
        /// </summary>
        public string Reserve
        {
            get 
            {
                if (string.IsNullOrEmpty(_reserve))
                    return RESERVE_CONST  ;

                return _reserve; 
            }
            set { _reserve = value; }
        }
		#endregion 
	}
}
